package com.bw.liuyushan.zhuangao4_mvptest1.Utils;

import com.bw.liuyushan.zhuangao4_mvptest1.BaseUrl.APIBanner;
import com.bw.liuyushan.zhuangao4_mvptest1.BaseUrl.APIFood;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * ZhuanGao4_MVPTest1
 * file name is : FoodrManager
 * created by Ender on 2021/8/17 8:36.
 * author : Liuyushan
 * Describe(作用):单例封装RxJava Retrofit OkHttp网络拦截器
 */
public class FoodrManager {
    private static FoodrManager foodrManager;

    public static FoodrManager getInstance() {
        if (foodrManager == null) {
            foodrManager = new FoodrManager();
        }
        return foodrManager;
    }

    private Retrofit retrofit;

    public Retrofit getRetrofit() {
        if (retrofit == null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(APIFood.url)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(new OkHttpClient.Builder()//添加OkHttp网络拦截器
                            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                            .build())
                    .build();
        }
        return retrofit;
    }
}
